﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Security;
using DR.WebUI.Models.Account;
using System.Web.Security;

namespace DR.WebUI.Code.ModelBinders
{
    public class CurrentUserModelBinder : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {

            MembershipUser user = Membership.GetUser();            
            if (user != null)
            {
                return new CurrentUser() { Login = user.UserName, UserID = (Guid)user.ProviderUserKey };
            }
            else
            {
                return null;
            }
        }

    }
}